﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;

namespace CADTool.DotNetARX
{
    public static class ArcTool
    {
        /// <summary>
        /// 三点画圆弧
        /// </summary>
        /// <param name="arc">圆弧对象</param>
        /// <param name="startPoint">圆弧起始</param>
        /// <param name="pointOnArc">圆弧上的一点</param>
        /// <param name="endPoint">圆弧终点</param>
        public static void CreateArc(this Arc arc, Point3d startPoint, Point3d pointOnArc, Point3d endPoint)
        {
            //创建一个几何类的圆弧对象
            CircularArc3d geArc = new CircularArc3d(startPoint, pointOnArc, endPoint);
            //将几何类圆弧对象的圆心和半径赋值给圆弧
            Point3d centerPoint = geArc.Center;
            arc.Center = centerPoint;
            arc.Radius = geArc.Radius;
            //计算起始和终止角度
            arc.StartAngle = startPoint.AngleFromXAis(centerPoint);
            arc.EndAngle = endPoint.AngleFromXAis(centerPoint);
        }
        /// <summary>
        /// 计算两点确定的向量与X轴正方向的夹角
        /// </summary>
        /// <param name="pt1"></param>
        /// <param name="pt2"></param>
        /// <returns></returns>
        public static double AngleFromXAis(this Point3d pt1, Point3d pt2)
        {
            //构建一个从第一点到第二点所确定的矢量
            Vector2d vector = new Vector2d(pt1.X - pt2.X, pt1.Y - pt2.Y);
            //返回该矢量和X轴正半轴的角度
            return vector.Angle;
        }
    }
}
